package com.hooper.controller;

import com.hooper.common.Result;
import com.hooper.model.dto.UserRoleDto;
import com.hooper.model.vo.UserRoleChangeVo;
import com.hooper.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "用户角色管理")
@Slf4j
@RestController
@RequestMapping("/admin/system/user-role")
public class UserRoleController {

    @Resource
    private UserRoleService userRoleService;


    @ApiOperation("新增用户角色")
    @PostMapping("assign-role")
    public Result<Void> save(@RequestBody(required = true) UserRoleChangeVo changeVo) {
        userRoleService.addUserRole(changeVo);
        return Result.ok();
    }

    @ApiOperation("通过id获取用户角色")
    @GetMapping("/{id}")
    public Result<UserRoleDto> getById(@PathVariable Long id) {
        return Result.ok(userRoleService.getUserRolesById(id));
    }
}